package com.unipay.oss;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.PutObjectResult;

import java.io.File;

/**
 * @Project: yitong_parent
 * @Author: Chenmy
 * @Time: 2023-10-10 12:43:51
 * @Desc: TODO
 */

public class S3Test {
    public static void main(String[] args) {
        //创建 s3 对象
        AwsClientBuilder.EndpointConfiguration endpointConfig =
                new AwsClientBuilder.EndpointConfiguration("http://oss.ts-pfecs.epay", Region.getRegion(Regions.DEFAULT_REGION).getName());

        AWSCredentials awsCredentials = new BasicAWSCredentials("BKWF5K44NSW2UEY8D835", "8utPBRmhy9kRdtDX4LT6K4Y46qo5zdevE1HcD4ng");
        AWSCredentialsProvider awsCredentialsProvider = new AWSStaticCredentialsProvider(awsCredentials);
        ClientConfiguration clientConfig = new ClientConfiguration();
        clientConfig.setProtocol(Protocol.HTTP);

        AmazonS3 S3client = AmazonS3Client.builder()
                .withEndpointConfiguration(endpointConfig)
                .withClientConfiguration(clientConfig)
                .withCredentials(awsCredentialsProvider)
                .disableChunkedEncoding()
                .withPathStyleAccessEnabled(true)
                .withForceGlobalBucketAccessEnabled(true)
                .build();

        PutObjectResult putObjectResult = S3client.putObject("ts-bdcs", "/sftp/provinceBusiness", new File("E:\\JAVA\\ssm\\Yitong\\yitong_parent\\service\\service-oss\\src\\main\\java\\com\\unipay\\oss\\test.txt"));
        System.out.println(putObjectResult);
    }
}
